﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using igflow.Components;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace igflow
{
    class igGUIRenderer : igComponent
    {
        public Mesh mesh;
        BasicEffect effect;
        public override void Init()
        {
            effect = new BasicEffect(World.Graphics.GraphicsDevice, null);
            //quadEffect.EnableDefaultLighting();
            effect.VertexColorEnabled = true;
            effect.World = Matrix.Identity;
            //effect.TextureEnabled = true;

            base.Init();
        }

        public override void OnGUI()
        {
            effect.Projection = World.currentCamera.Projection;
            effect.View = gameObject.WorldMatrix * World.currentCamera.View;
            World.Graphics.GraphicsDevice.RenderState.CullMode = CullMode.None;
            World.Graphics.GraphicsDevice.VertexDeclaration = mesh.vertexDeclaration;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                World.Graphics.GraphicsDevice.DrawUserIndexedPrimitives
                   <VertexPositionColorTexture>(
                   PrimitiveType.TriangleList,
                   mesh.Vertices, 0, 4,
                   mesh.Indexes, 0, 2);

                pass.End();
            }
            effect.End();
        }
    }
}
